package cn.com.fuhuitong.popup

import android.content.Context
import android.view.View
import cn.com.fuhuitong.R
import kotlinx.android.synthetic.main.popup_confirm_cancel.view.*
import razerdp.basepopup.BasePopupWindow

class ConfirmCancelPopup(
    context: Context,
    val onConfirm: (any: Any?, action: Action?) -> Unit,
    val onCancel: (any: Any?, action: Action?) -> Unit
) : BasePopupWindow(context) {

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_confirm_cancel)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        contentView.tvPopupConfirm.setOnClickListener {
            this.onConfirm(any, action)
        }
        contentView.tvPopupCancel.setOnClickListener {
            this.onCancel(any, action)
        }
    }

    private var action: Action? = null
    private var any: Any? = null

    fun setAction(action: Action?): ConfirmCancelPopup {
        this.action = action
        return this
    }

    fun setAny(any: Any?): ConfirmCancelPopup {
        this.any = any
        return this
    }

    fun setMessage(message: String): ConfirmCancelPopup {
        contentView.tvPopupMessage.text = message
        return this
    }

    fun setGoneConfirm(isGone: Boolean): ConfirmCancelPopup {
        contentView.tvPopupConfirm.visibility =
            if (isGone) View.GONE else View.VISIBLE
        return this
    }

    fun setGoneCancel(isGone: Boolean): ConfirmCancelPopup {
        contentView.tvPopupCancel.visibility =
            if (isGone) View.GONE else View.VISIBLE
        contentView.tvPopupLine.visibility =
            if (isGone) View.GONE else View.VISIBLE
        return this
    }

    enum class Action {
        CONFIRM_TASK, CONFIRM_PICKUP, CONFIRM_GIVE, CONFIRM_CALL, CONFIRM_NAVIGATION, CONFIRM_SETTLE
    }

    //

    //AnchorRoomActivity.start(context, it.wy_room_id.toString(), "")

}